/*
# Miahx© 框架消息 FastDDS API 包装器的 Nodejs C 接口测试文件

Version: 0.4.10,
Last updated: October 15, 2024

## Contributor(s)
* YAO Naiming <[naiming@iscas.ac.cn](mailto:naiming@iscas.ac.cn)>

## Change log
### v0.4.10
- .15: [新增] 迁移实现

---
Copyright © 2024-2025 MIAHX Contributors, ISCAS, and ASIC. All Rights Reserved.
Licensed under Apache-2.0.
*/

#include <iostream>
#include <mutex>
#include <thread>
#include "../src/miahx_fastdds_api/include/miahx_nodejs_wrapper.h"

using namespace std;


void thread_func(unique_lock<mutex> &lock, condition_variable &cond) {
    this_thread::sleep_for(chrono::seconds(5));
    cond.notify_all();
}

void on_bng_classical_data_available(const char *json, void *user_state) {
    string str((char *) user_state);
    cout << json << ", user_state: " << str << endl;
}

int main() {
    mutex mtx;
    unique_lock<mutex> lock(mtx);
    condition_variable cond;
    thread th(thread_func, ref(lock), ref(cond));
    th.detach();

    auto support = MiahxWrapperNodejs::get_instance();
    string user_state = "test_user_state";
    support->set_bng_classical_data_provider(on_bng_classical_data_available,
                                             (void *) user_state.c_str());

    cond.wait(lock);

    return 0;
}
